﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Light_Calendar
{
    /// <summary>
    /// Interaction logic for CalendarCell.xaml
    /// </summary>
    public partial class CalendarCell : UserControl
    {
        private Light_Calendar.MainWindow mainWindow;
        private DateTime date;
        private List<CalendarEvent> events;

        public DateTime Date
        {
            get { return date; }
            set
            {
                date = value;
                dateText.Text = date.Day.ToString();
                if (date.DayOfWeek == DayOfWeek.Sunday) dateText.Foreground = Brushes.DarkRed;
                if (date == DateTime.Today)
                {
                    Background = Brushes.LightYellow;
                    dateText.FontWeight = FontWeights.Bold;
                }
            }
        }

        public List<CalendarEvent> Events
        {
            get { return events; }
            set
            {
                events = value;
                eventsList.Children.Clear();
                foreach (CalendarEvent e in events) eventsList.Children.Add(new EventBlock(Date, e));
            }
        }

        public CalendarCell()
        {
            InitializeComponent();

            mainWindow = (Light_Calendar.MainWindow)App.Current.MainWindow;
        }

        private void new_Click(object sender, RoutedEventArgs e)
        {
            if (!mainWindow.IsEditing) mainWindow.New(Date);
        }

        private void today_Click(object sender, RoutedEventArgs e)
        {
            mainWindow.FocusDate(DateTime.Today);
        }
    }
}
